package daobeauty.proxy.reflection;

import java.lang.reflect.Proxy;

import org.hibernate.SessionFactory;

import daobeauty.interceptor.MethodInterceptor;
import daobeauty.proxy.ProxyProvider;

/**
 * Created 08.09.2008
 * @author M. Serhat Cinar
 *
 */
public class ReflectionProxyProvider implements ProxyProvider {

	/* (non-Javadoc)
	 * @see daobeauty.bytecode.ByteCodeProvider#generateProxy(java.lang.Class, java.lang.Class[])
	 */
	public Object generateProxy(Class[] interfaces, SessionFactory sessionFactory, Class domainClass, Object target, Object [] delegates) {
		if (target!=null){
			throw new IllegalArgumentException("jdk reflection can not proxy classes");
		}
		
		return Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, new InvocationHandlerAdapter(MethodInterceptor.create(sessionFactory, domainClass, target, delegates, interfaces))); 
	}
}
